package com.林子祺.全名健康管理系统.dao.loginandregister;

import java.sql.*;

public class RegisterAccount {

    static boolean end = false;

    public static boolean addAccount(String name,String password,String email,String gender,int age,double height,double weight) {
        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;
        String n = name;
        String p = password;
        try {
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/account?useUnicode=true&characterEncoding=utf-8", "root", "blink102417");

            String sql = "insert into login values("+"'"+email+"','"+name+"','"+password+"',"+age+",'"+gender+"',"+height+","+weight+")";

            stmt = conn.createStatement();

            stmt.execute(sql);

            end = true;

        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            if(rs != null) {
                try {
                    rs.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
            if(stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
            if(conn != null) {
                try {
                    conn.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
        }
        if(end == true){
            end = false;
            return true;
        }
        else
            return false;
    }
}
